$(() => {
    // 热门排行
    const getRankList = () => {
        myajax('GET', '/index/rank', {}, (res) => {
            // console.log(res);
            const htmlSty = template('rank', res)
            $('#Rank').html(htmlSty)
        })
    }
    getRankList()
    // 最新评论
    const getLatestList = () => {
        myajax('GET', '/index/latest_comment', {}, (res) => {
            // console.log(res);
            const htmlSty = template('comment', res)
            $('.comment_list').html(htmlSty)
        })
    }
    getLatestList()
    // 焦点关注
    const getAttentionList = () => {
        myajax('GET', '/index/attention', {}, (res) => {
            // console.log(res);
            const htmlSty = template('attention', res)
            $('.guanzhu_list').html(htmlSty)
        })
    }
    getAttentionList()
    // 文章详细内容
    let url = new URLSearchParams(location.search)
    let id = url.get('id')
    // let id = 12
    const getArtitleList = () => {
        myajax('GET', '/index/article', { id }, (res) => {
            console.log(id);
            // console.log(id);
            let htmlSty = template('artitle', res.data)
            $('#getarticle').html(htmlSty)
        })
    }
    getArtitleList()

    const getCommentList = () => {
        myajax('GET', '/index/get_comment', { articleId: id }, (res) => {
            console.log(res);
            let htmlSty = template('Comment', res)
            $('.comment_detail_list').html(htmlSty)
            $('.comment_count').html(res.data.length + '条评论');
        })
    }
    getCommentList()

    const getStatementList = () => {
        $('form').on('click', '.comment_sub', (e) => {
            e.preventDefault();
            // console.log(2);
            let parms = {
                author: $('.comment_name').val(),
                content: $('.comment_input').val(),
                articleId: id,
            }
            myajax('POST', '/index/post_comment', parms, function (res) {
                res.code == 200 ? layer.msg('发表成功') : layer.msg(res.msg)
            });
        })
    }
    getStatementList()
})